﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;
using System.Web.Script.Serialization;
using RoadTeam.BLL;
using System.Data;
using RoadTeam.Pub;
using RoadTeam.Standard;
using System.Text.RegularExpressions;
public partial class 对接测试页面_InspectHouse : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        InspectHouseBLL bll = new InspectHouseBLL();
        JavaScriptSerializer jscvt = new JavaScriptSerializer();
        CsInspectHouse model = jscvt.Deserialize<CsInspectHouse>(TextBox1.Text);
        if (model.Item.Length == 0) return;
        DataTable dt = bll.GetCsInspectHouseDataForEnptyTable();
        DataRow dr;
        foreach (InspectHouse item in model.Item)
        {
            dr = dt.NewRow();
            dr["InspectHouseIdentifier"] = CreateIdentifier.GetIdentifier();
            dr["InspectHouseNo"] = item.InspectHouseNo;
            dr["InspectHouseDate"] = item.InspectHouseDate;
            dr["InspectHouseUnitNo"] = item.InspectHouseUnitNo;
            dr["InspectHouseSituation"] = item.InspectHouseSituation;
            dr["InspectHouseAddress"] = item.InspectHouseAddress;
            dr["InspectHouseContact"] = item.InspectHouseContact;
            dr["InspectHouseContactPhone"] = item.InspectHouseContactPhone;
            dr["InspectHouseCreater"] = item.InspectHouseCreater;
            dr["InspectHouseCreatDate"] = item.InspectHouseCreatDate;
            dr["InspectHouseRemark"] = item.InspectHouseRemark;
            item.InspectHouseIdentifier = dr["InspectHouseIdentifier"].ToString();
            dt.Rows.Add(dr);
        }

        bll.Insert(dt, TextBox1.Text);
        Response.Write(jscvt.Serialize(model));
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        List<InspectHouse> li = new List<InspectHouse>();
        InspectHouse House = new InspectHouse();
        House.InspectHouseIdentifier = CreateIdentifier.GetIdentifier();
        House.InspectHouseNo = @"1008600001";
        House.InspectHouseDate = DateTime.Now.ToString();
        House.InspectHouseUnitNo = @"1000001";
        House.InspectHouseSituation = @"检验这个房子各项指标是否合格";
        House.InspectHouseAddress = @"广州市天河区天河北路689号七楼711";
        House.InspectHouseContact = @"张三";
        House.InspectHouseContactPhone = @"10086";
        House.InspectHouseCreater = @"张三";
        House.InspectHouseCreatDate = DateTime.Now.ToString();
        House.InspectHouseRemark = @"这个是备注!!";
        li.Add(House);
        House = new InspectHouse();
        House.InspectHouseIdentifier = CreateIdentifier.GetIdentifier();
        House.InspectHouseNo = @"1008600002";
        House.InspectHouseDate = DateTime.Now.ToString();
        House.InspectHouseUnitNo = @"1000002";
        House.InspectHouseSituation = @"检验这个房子各项指标是否合格";
        House.InspectHouseAddress = @"广州市天河区天河北路689号七楼712";
        House.InspectHouseContact = @"李四";
        House.InspectHouseContactPhone = @"10086";
        House.InspectHouseCreater = @"李四";
        House.InspectHouseCreatDate = DateTime.Now.ToString();
        House.InspectHouseRemark = @"这个是备注!!";
        li.Add(House);
        House = new InspectHouse();
        House.InspectHouseIdentifier = CreateIdentifier.GetIdentifier();
        House.InspectHouseNo = @"1008600003";
        House.InspectHouseDate = DateTime.Now.ToString();
        House.InspectHouseUnitNo = @"1000003";
        House.InspectHouseSituation = @"检验这个房子各项指标是否合格";
        House.InspectHouseAddress = @"广州市天河区天河北路689号七楼713";
        House.InspectHouseContact = @"王五";
        House.InspectHouseContactPhone = @"10086";
        House.InspectHouseCreater = @"王五";
        House.InspectHouseCreatDate = DateTime.Now.ToString();
        House.InspectHouseRemark = @"这个是备注!!";
        li.Add(House);

        JavaScriptSerializer jscvt = new JavaScriptSerializer();
        CsInspectHouse model = new CsInspectHouse();
        model.Item = li.ToArray();

        string str = jscvt.Serialize(model);

        str = Regex.Replace(str, @"\\/Date\((\d+)\)\\/", match =>
        {
            DateTime dt = new DateTime(1970, 1, 1);
            dt = dt.AddMilliseconds(long.Parse(match.Groups[1].Value));
            dt = dt.ToLocalTime();
            return dt.ToString("yyyy-MM-dd HH:mm:ss");
        });
        TextBox1.Text = str;
    }
}

//public class InspectHouse
//{
//    [XmlElement(ElementName = "InspectHouseIdentifier", Type = typeof(string))]
//    public String InspectHouseIdentifier;
//    [XmlElement(ElementName = "InspectHouseNo", Type = typeof(string))]
//    public String InspectHouseNo;
//    [XmlElement(ElementName = "InspectHouseDate", Type = typeof(DateTime))]
//    public DateTime InspectHouseDate;
//    [XmlElement(ElementName = "InspectHouseUnitNo", Type = typeof(string))]
//    public String InspectHouseUnitNo;
//    [XmlElement(ElementName = "InspectHouseSituation", Type = typeof(string))]
//    public String InspectHouseSituation;
//    [XmlElement(ElementName = "InspectHouseAddress", Type = typeof(string))]
//    public String InspectHouseAddress;
//    [XmlElement(ElementName = "InspectHouseContact", Type = typeof(string))]
//    public String InspectHouseContact;
//    [XmlElement(ElementName = "InspectHouseContactPhone", Type = typeof(string))]
//    public String InspectHouseContactPhone;
//    [XmlElement(ElementName = "InspectHouseCreater", Type = typeof(string))]
//    public String InspectHouseCreater;
//    [XmlElement(ElementName = "InspectHouseCreatDate", Type = typeof(string))]
//    public String InspectHouseCreatDate;
//    [XmlElement(ElementName = "InspectHouseRemark", Type = typeof(string))]
//    public String InspectHouseRemark;
//}

//public class CsInspectHouse
//{
//    [XmlElement(ElementName = "Item")]
//    public InspectHouse[] Item;
//}





